package cn.iocoder.yudao.module.infrastructure.file.api;

import cn.iocoder.yudao.module.api.infrastructure.file.FileApi;
import cn.iocoder.yudao.module.infrastructure.file.dal.dataobject.FileDO;
import cn.iocoder.yudao.module.infrastructure.file.service.FileService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * 文件 API 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class FileApiImpl implements FileApi {

    @Resource
    private FileService fileService;

    @Override
    public String createFile(String name, String path, byte[] content) {
        return fileService.createFile(name, path, content);
    }

    @Override
    public String createFile(byte[] content, String name, String directory, String type) {
        return fileService.createFile(content, name, directory, type);
    }

    @Override // FIXED 新增
    public String getUrlByPath(String path) {
        FileDO fileDO = fileService.getFileByPath(path);
        if (fileDO != null) {
            return fileDO.getUrl();
        }
        return null;
    }

}
